package rabbitMQ;

import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitSerializable {

    @Bean
    public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
        RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
        rabbitTemplate.setConfirmCallback((correlationData, ack, cause) -> {
            System.out.println("----------------");
            System.out.println(correlationData);
            System.out.println(ack);
            System.out.println(cause);
        });
        rabbitTemplate.setReturnCallback((message, replyCode, replyText,
                exchange, routingKey) -> {
            System.out.println("===================");
            System.out.println(message);
            System.out.println(replyCode);
        });
        rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
        return rabbitTemplate;
    }

//    @Bean
//    public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
//        RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
//        rabbitAdmin.setAutoStartup(true);
//        return rabbitAdmin;
//    }
//
//    @Bean
//    DirectExchange directExchange(ConnectionFactory connectionFactory){
//        DirectExchange messageDirectExchange=new DirectExchange("ltTestExchange1");
//        rabbitAdmin(connectionFactory).declareExchange(messageDirectExchange);
//        return messageDirectExchange;
//    }
//
//    @Bean
//    Queue messageDirectQueue(ConnectionFactory connectionFactory){
//        Queue queue=new Queue("ltTestQueue1",true);
//        rabbitAdmin(connectionFactory).declareQueue(queue);
//        return queue;
//    }
//
//    @Bean
//    Binding bindingMessageDirectExchangeQueue(ConnectionFactory connectionFactory, Queue messageDirectQueue, DirectExchange directExchange){
//        Binding binding= BindingBuilder.bind(messageDirectQueue).to(directExchange).with("ltTestRoutingKey1");
//        rabbitAdmin(connectionFactory).declareBinding(binding);
//        return binding;
//    }

}
